<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-touch-fullscreen" content="yes">
		<meta name="format-detection" content="telephone=no;email=no">

		<link rel="stylesheet" href="../../css/mui.min.css">
		<title>我的评论</title>
		<style>
			.mui-media-body{
				color: #000;
			}
			
			.mui-media-body p{
				margin-top: 10px;
			}
		</style>
	</head>

	<body>
		<!-- 刷新容器 -->
		<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
			<div class="mui-scroll">
				<!--数据列表-->
				<ul class="mui-table-view" id="myCommentsUl">
					
				</ul>
			</div>
		</div>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/mui.lazyload.js"></script>
		<script src="../../js/mui.lazyload.img.js"></script>
		<script src="../../js/template.js"></script>
		<script src="../../js/common.js"></script>

		<!-- 评论模板 -->
		<script id="myComments" type="text/html">
			{{each data as value i}}
			<li class="mui-table-view-cell  mui-media" newsId="{{value.newsId}}" newsTitle="{{value.newsTitle}}" >
				<div class="mui-slider-handle">
					<a href="javascript:;">
						<div class="mui-media-body">
							{{value.newsTitle}}
							<p>{{value.reply}}</p>
						</div>
					</a>
				</div>
			</li>
			{{/each}}
		</script>

		<script>
			var startIndex = 0;
			mui.init({
				swipeBack: true, //启用右滑关闭功能
				pullRefresh: {
					container: '#pullrefresh',
					up: {
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}
			});
			//添加night自定义事件监听
			/*window.addEventListener('night', function(event) {
				lkg.nightMode();
			});*/
			/**
			 * 上拉加载具体业务实现
			 */
			function pullupRefresh() {
				var uuid = plus.device.uuid; //获取设备的唯一标识
				plus.nativeUI.showWaiting("", {width: "50px", height: "50px", background: "#efeff4", style: "black"});
				//setTimeout(function() {
					mui.ajax({
						url: baseUrl + '/my/pllis?devicesId=' + uuid + '&start=' + startIndex + '&length=5',
						dataType: 'json',
						type: 'get',
						success: function(data) {
							if (data.returnFlag == 0) {
								mui('#pullrefresh').pullRefresh().endPullupToRefresh(data.data.length == 0); //参数为true代表没有更多数据了。
								if (data.data.length > 0) {
									var html = template('myComments', data);
									document.getElementById('myCommentsUl').innerHTML += html;
									startIndex += data.data.length;
								}
							}
							plus.nativeUI.closeWaiting();
						},
						error: function(xhr, type, errorThrown) {
							//异常处理；
							throwGetNewsError();
						}
					});
				//}, 1000);
			}
			
			mui("#myCommentsUl").on("tap", "li", function() {
				var newsId = this.getAttribute('newsId');
				var newsTitle = this.getAttribute('newsTitle');
				
				//打开详情页面          
				mui.openWindow({
					url: 'my_comments_detail.html',
					id: 'my_comments_detail.html',
					extras: {
						newsId: newsId,
						newsTitle: newsTitle
					},
					waiting: {
						autoShow: false
					},
					createNew: true //是否重复创建同样id的webview，默认为false:不重复创建，直接显示
				});
			});

			function refreshList() {
				startIndex = 0;
				document.getElementById('myCommentsUl').innerHTML = "";
				mui('#pullrefresh').pullRefresh().pullupLoading();
				mui('#pullrefresh').pullRefresh().refresh(true);
			}
			
			if (mui.os.plus) {
				mui.plusReady(function() {
					setTimeout(function() {
						mui('#pullrefresh').pullRefresh().pullupLoading();
					}, 100);
				});
			} else {
				mui.ready(function() {
					mui('#pullrefresh').pullRefresh().pullupLoading();
				});
			}
		</script>
	</body>

</html>